#include "client.h"
#include "ui_client.h"

Client::Client(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Client)
{
    createConnection2();//链接数据库
    ui->setupUi(this);
    setWindowTitle(tr("登录"));
    ui->lineEdit_2->setEchoMode(QLineEdit::Password);
    QMovie *movie1 = new QMovie("D:/1.jpg");
    ui->label_3->setMovie(movie1);
    ui->label_3->setScaledContents(true);
    movie1->start();


}

Client::~Client()
{
    delete ui;
}
//显示密码
void Client::on_checkBox_2_clicked()
{
    static int flag =1;
    if(flag)
    {
        ui->lineEdit_2->setEchoMode(QLineEdit::Normal);
        flag=0;
    }
    else
    {
        ui->lineEdit_2->setEchoMode(QLineEdit::Password);
        flag=1;
    }
}
//记住密码
void Client::on_checkBox_clicked()
{
    static int flag1 =1;
    //-------------------------------------------------------------------------------------
    //数据库处理
    QSqlDatabase db1 = QSqlDatabase::database("connection1"); //得到指定连接名称数据库

    QSqlQuery query1(db1);
    query1.exec("select * from data1"); //执行sql语句
    //---------------------------------------------------------------------------------------
    if(flag1)
    {
        while (query1.next())
        {
            if(query1.value(0).toString() == ui->comboBox->currentText())
            {
                QString temp = query1.value(1).toString();
                ui->lineEdit_2->setText(temp);
                flag1=0;
                break;
            }
        }
    }
    else
    {
        ui->lineEdit_2->setText("");
        flag1=1;
    }

}
//登录
void Client::on_pushButton_clicked()
{

    //-------------------------------------------------------------------------------------
    //数据库处理
    QSqlDatabase db1 = QSqlDatabase::database("connection1"); //得到指定连接名称数据库

    QSqlQuery query1(db1);
    query1.exec("select * from data1"); //执行sql语句
    //---------------------------------------------------------------------------------------
    //密码判断对比
    while (query1.next())
    {
        if(query1.value(0).toString() == ui->comboBox->currentText())
        {
            if(query1.value(1).toString() == ui->lineEdit_2->text())
            {
                client3 *configWindow = new client3;
                configWindow->show();
                close();
                break;
            }

        }

    }
}
//注册
void Client::on_pushButton_2_clicked()
{
    client2 *configWindow = new client2;
    configWindow->show();
    QString idValue = configWindow->Returnid();
    // 添加新注册的账号到 comboBox 中
    ui->comboBox->addItem(idValue);

}




